package com.paomi.client.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.paomi.client.R;


public class ToastUtil {
    public static ToastUtil mToast;
    private Toast toast;
    public Typeface iconfont;

    private ToastUtil() {
    }

    public static ToastUtil getToastEmail() {
        if (mToast == null) {
            mToast = new ToastUtil();
        }
        return mToast;
    }

    /**
     * 显示
     */
    @SuppressLint("WrongConstant")
    public void ToastShow(Context context, ViewGroup root, int pos, int layout, String textToast) {
        iconfont = Typeface.createFromAsset(context.getAssets(), "iconfont.ttf");
        View view = LayoutInflater.from(context).inflate(layout, root);
        TextView text = (TextView) view.findViewById(R.id.tv_img);
        TextView textShow = (TextView) view.findViewById(R.id.textToast);
        text.setTypeface(iconfont);
        if (!textToast.equals("")) {
            textShow.setText(textToast); // 设置显示文字
        }
        toast = new Toast(context);
        if (pos == 1) {
            toast.setGravity(Gravity.CENTER, 0, 0); // Toast显示的位置
        }
        toast.setDuration(2000); // Toast显示的时间
        toast.setView(view);
        toast.show();
    }

    /**
     * 显示签到
     */
    @SuppressLint("WrongConstant")
    public void ToastSign(Context context, ViewGroup root, int pos, int layout, String textToast) {
        View view = LayoutInflater.from(context).inflate(layout, root);
        TextView textShow = (TextView) view.findViewById(R.id.textToast);
        textShow.setText(textToast); // 设置显示文字
        toast = new Toast(context);
        if (pos == 1) {
            toast.setGravity(Gravity.CENTER, 0, 0); // Toast显示的位置
        }
        toast.setDuration(2000); // Toast显示的时间
        toast.setView(view);
        toast.show();
    }

    public void ToastCancel() {
        if (toast != null) {
            toast.cancel();
        }
    }
}
